package tool

// 栈只有一个指针head,先进后出

type MyShed[T MyInt] struct {
	Head *Node1[T]

	size T
}

func (receiver *MyShed[T]) ShedSize() T {
	return receiver.size
}

func (receiver *MyShed[T]) IsEmpty() bool {
	return receiver.size == 0
}
func (receiver *MyShed[T]) Offer(v T) {
	var n = Node1[T]{Value: v, Next: nil}
	if receiver.Head == nil {
		receiver.Head = &n

	} else {
		n.Next = receiver.Head
		receiver.Head = &n
	}

	receiver.size++
}
func (receiver *MyShed[T]) Poll() T {
	var v T = -1
	if receiver.size == 1 {
		v = receiver.Head.Value
		receiver.Head = nil
		receiver.size--

	} else {
		v = receiver.Head.Value
		receiver.Head = receiver.Head.Next
		receiver.size--
	}
	return v

}
func (receiver MyShed[T]) Peek() T {
	var v T = -1

	if receiver.Head != nil {
		v = receiver.Head.Value
	}

	return v
}
